package com.mxs.qrcode.utils;

import com.github.houbb.pinyin.api.impl.Pinyin;
import com.github.houbb.pinyin.api.impl.PinyinContext;
import com.github.houbb.pinyin.spi.*;
import com.github.houbb.pinyin.support.chinese.SimplePinyinChinese;
import com.github.houbb.pinyin.support.data.PinyinData;
import com.github.houbb.pinyin.support.segment.DefaultPinyinSegment;
import com.github.houbb.pinyin.support.style.DefaultPinyinToneStyle;
import com.github.houbb.pinyin.support.style.InputToneStyle;
import com.github.houbb.pinyin.support.tone.DefaultPinyinTone;

public class PinyinUtil {

    public static String getPinyin(String str){
        //jiàoyùbùtōngbàohúběigāokǎoshēngzuòbìxìjié
        IPinyinToneStyle style =new DefaultPinyinToneStyle();
        //IPinyinToneStyle style =new FirstLetterPinyinToneStyle();
        //ganmane
        //IPinyinToneStyle style =new InputToneStyle();
        //IPinyinToneStyle style =new NormalPinyinToneStyle();
        //jiao4yu4bu4tong1bao4hu2bei3gao1kao3sheng1zuo4bi4xi4jie2
        //IPinyinToneStyle style =new NumLastPinyinToneStyle();
        IPinyinSegment segment = new DefaultPinyinSegment();
        //IPinyinSegment segment = new CharPinyinSegment();
        IPinyinData data = new PinyinData();
        IPinyinChinese chinese= new SimplePinyinChinese();
        IPinyinTone tone = new DefaultPinyinTone();

        PinyinContext context = PinyinContext.newInstance();
        context.style(style);
        context.segment(segment);
        context.chinese(chinese);
        context.tone(tone);
        context.data(data);
        context.connector(" ");
        Pinyin pinyin = new Pinyin();
        String x = pinyin.toPinyin(str,context);
        return x;
    }
}
